module dbg_mod; 
use sys_setup_mod;
implicit none;  
!logical, save :: VEC_DBG_ON ;
integer, save :: VEC_DBG_VIEW_N = 10;
contains;

subroutine dbg_vec(info, v, on);  implicit none;  
  character(LEN=*), intent(in) :: info;   
  real(R14), dimension(:), intent(in) :: v; 
  logical, optional, intent(in) :: on;  
  integer :: i, n;
  if (present(on) .AND. (.NOT. on)) return;
  
  if (SIZE(v) <= VEC_DBG_VIEW_N) then
    write(*,*) info, (v(i), i = LBOUND(v, 1), UBOUND(v, 1));
  else
    n = VEC_DBG_VIEW_N / 2;
    write(*,*) info, "(", LBOUND(v, 1), ":", UBOUND(v, 1), ")=", &
    & (v(i), i = LBOUND(v, 1), LBOUND(v, 1) + n - 1), ", ..., ", &
    & (v(i), i = UBOUND(v, 1) - n + 1, UBOUND(v, 1));
  end if
end subroutine

subroutine dbg_info(info, on);  implicit none;  
  character(LEN=*), intent(in) :: info;   
  logical, optional, intent(in) :: on;  
  if (present(on) .AND. (.NOT. on)) return;  
  write(*,*) info;
end subroutine

subroutine dbg_str(info, str, on);  implicit none;  
  character(LEN=*), intent(in) :: info, str;   
  logical, optional, intent(in) :: on;  
  if (present(on) .AND. (.NOT. on)) return;  
  write(*,*) info, "'", str, "'";
end subroutine

subroutine dbg_bool(info, v, on);  implicit none;  
  character(LEN=*), intent(in) :: info;   
  logical, intent(in) :: v; 
  logical, optional, intent(in) :: on;  
  if (present(on) .AND. (.NOT. on)) return;  
  write(*,*) info, v;
end subroutine

subroutine dbg_real(info, v, on);  implicit none;  
  character(LEN=*), intent(in) :: info;   
  real(R14), intent(in) :: v; 
  logical, optional, intent(in) :: on;  
  if (present(on) .AND. (.NOT. on)) return;  
  write(*,*) info, v;
end subroutine

subroutine dbg_int(info, v, on);  implicit none;  
  character(LEN=*), intent(in) :: info;   
  integer, intent(in) :: v; 
  logical, optional, intent(in) :: on;  
  if (present(on) .AND. (.NOT. on)) return;  
  write(*,*) info, v;
end subroutine
end module 